import Vue from 'vue'
import Vuex from 'vuex'
import vuexP from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[],//存放任务
    bgColor:'red'
  },
  getters: {
  },
  mutations: {
    addTask(state,title){
        console.log(title);
        state.list.push({
            title:title,
            id:new Date().getTime(),//表示id
            status:0,//0表示未完成，1表示已完成 2表示已取消
        })


    },
    changeStatus(state,obj){
        console.log(obj);
        let {id,status} = obj
        let index = state.list.findIndex(item=>item.id == id)
        state.list[index].status = status
    },
    changeItem(state,obj){
        // let {id,status} = obj
        // let index = state.list.findIndex(item=>item.id == id)
        // state.list[index].status = status
    },
    setColor(state){
        console.log(Math.random().toString(16));
        state.bgColor = '#'+Math.random().toString(16).slice(2,6)

        // rgb(255,255,255)
        // // Math.random() 或者的0-1之前的随机数，取不到1，如果想要让他取值在0-255之前  必须*256 
        // let r = parseInt(Math.random()*256)
        // let g = parseInt(Math.random()*256)
        // let b = parseInt(Math.random()*256)
        // state.bgColor = `rgb(${r},${g},${b})`

    },
    updateList(state,obj){
      let {index,editValue} = obj
      state.list[index].title = editValue

    },
    del(state,id){
        let index= state.list.findIndex(item=>item.id == id)
        state.list.splice(index,1)

    }

  },
  actions: {
  },
  modules: {
  },
  plugins:[vuexP()]
})
